package com.dkakunsi.monev.dao;

import java.util.List;

import org.hibernate.Query;
import org.springframework.stereotype.Repository;

import com.dkakunsi.monev.entity.Kegiatan;
import com.dkakunsi.monev.entity.Realisasi;
import com.dkakunsi.monev.util.MonevDataException;

@Repository("realisasiHibernateRepository")
public class RealisasiDao extends GenericDao<Realisasi> {
	@SuppressWarnings("unchecked")
	public List<Realisasi> get(Kegiatan kegiatan) throws MonevDataException {
		Query query = getSession().createQuery("SELECT r FROM Realisasi r WHERE r.kegiatan = :kegiatan ORDER BY r.bulan");
		query.setParameter("kegiatan", kegiatan);
		
		return checkNull(query.list());
	}

	@SuppressWarnings("unchecked")
	public Realisasi get(Kegiatan kegiatan, int bulan) throws MonevDataException {
		Query query = getSession().createQuery("SELECT r FROM Realisasi r WHERE r.kegiatan = :kegiatan AND r.bulan = :bulan");
		query.setParameter("kegiatan", kegiatan);
		query.setParameter("bulan", bulan);
		
		List<Realisasi> ls = checkNull(query.list());
		if(ls.size() > 0)
			return ls.get(0);
		return new Realisasi(kegiatan, bulan);
	}

	protected Realisasi isExist(Realisasi t) {
		// TODO Auto-generated method stub
		return null;
	}
}
